package com.ezmobo.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ezmobo.core.ServerContext;
import com.ezmobo.core.database.DynamicDataSource;
import com.ezmobo.service.TestDB;

public class TestServlet extends HttpServlet {
	private TestDB test;

	public void init() {
		System.out.println("创建实例");
		test = (TestDB) ServerContext.getBean(TestDB.class);
	}

	public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
		doPost(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
		try {
			System.out.println("我是doGet()方法！用来处理GET请求");
			response.setContentType("text/html;charset=GB2312");
			PrintWriter out = response.getWriter();
			out.println("<HTML>");
			out.println("<BODY>");
			out.println("这是Servlet的例子");
			out.println("</BODY>");
			out.println("</HTML>");
			// DynamicDataSource.setMimi();
			System.out.println("开始调用");
			test.add(999,"dddddddddddddddd");
			System.out.println("结束调用");
			// DynamicDataSource.setManager();
			// test.testStudent();
			// test.update();

		} catch (Exception e) {
			e.printStackTrace();

			response.setContentType("text/html;charset=GB2312");
			PrintWriter out = response.getWriter();
			out.println("<HTML>");
			out.println("<BODY>");
			out.println("异常测试");
			out.println("</BODY>");
			out.println("</HTML>");
		}

	}

	public void destroy() {
		super.destroy();
		System.out.println("我是destroy()方法！用来进行销毁实例的工作");
	}
}
